package com.explore.demo.controller;


import com.explore.demo.DTO.SearchDTO;
import com.explore.demo.VO.RecruitmentCreateVO;
import com.explore.demo.common.ServerResponse;
import com.explore.demo.pojo.RecruitCategory;
import com.explore.demo.pojo.Recruitment;
import com.explore.demo.service.RecruitmentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gaolainan
 * @since 2021-04-18
 */
@RestController
@RequestMapping("/recruitment")
public class RecruitmentController {

    @Resource
    private RecruitmentService recruitmentService;

    @GetMapping
    @ApiOperation("查询全部的招聘信息")
    public ServerResponse query(){
        return recruitmentService.queryAll();
    }

    @PostMapping
    @ApiOperation("创建一个招聘的信息")
    public ServerResponse addOne(@RequestBody Recruitment recruitment, HttpServletRequest request){
        return recruitmentService.addRecruitment(recruitment, request);
    }

    @DeleteMapping
    @ApiOperation("通过招聘信息的标题 删除招聘信息信息")
    public ServerResponse deleteByTitle(Integer id){
        return recruitmentService.deleteByTitle(id);
    }

    @PostMapping("/{title}")
    @ApiOperation("通过招聘信息的标题 查询招聘的相关信息")
    public ServerResponse queryByName(@PathVariable("title") String title){
        return recruitmentService.queryByTitle(title);
    }

    @PostMapping("/query_by_id")
    @ApiOperation("通过招聘信息的id 查询招聘的相关信息")
    public ServerResponse queryByName(@RequestParam("recruitmentId") Integer recruitmentId, HttpServletRequest request){
        return recruitmentService.queryByRecruitmentId(recruitmentId, request);
    }

    @PostMapping("/query")
    @ApiOperation("搜索框的模糊查询")
    public ServerResponse queryBySearchVO(SearchDTO searchDTO){
        return recruitmentService.queryAllBySearchVO(searchDTO);
    }


    @PostMapping("/create_recruitment")
    @ApiOperation("创建一个新的职位")
    public ServerResponse createRecruit(@RequestBody RecruitmentCreateVO recruitment, HttpServletRequest request){
        return recruitmentService.createRecruitment(recruitment.getRecruitment(), recruitment.getCategory(), recruitment.getWelfare(), request);
    }

    @PutMapping
    public ServerResponse updateRecruitment(@RequestBody Recruitment recruitment){
        return recruitmentService.updateRecruitment(recruitment);
    }

}

